package com.afterglow.yourlimitframework.handler;

import com.afterglow.yourlimitframework.excpetion.BaseException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Description:
 * Date 2024/08/30 16:15
 * 全类名 com.afterglow.yourlimitframework.handler.GlobalExceptionHandler
 * 全包名 com/afterglow/yourlimitframework/excpetion/GlobalExceptionHandler.java
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    // 处理自定义异常
    @ExceptionHandler(BaseException.class)
    public String handleCustomException(BaseException ex) {
        log.error("异常信息：{}", ex.getMessage());
       return ex.getMessage();
    }

    // 处理其他异常
    @ExceptionHandler(Exception.class)
    public String handleOtherExceptions(Exception ex) {
        log.error("异常信息：{}", ex.getMessage());
        return ex.getMessage();
    }
}
